/*
 *  Copyright (C) 2005-2007 Renier Roth
 *  www.renier.de
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package de.renier.jkeepass.actions;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.ImageIcon;

import de.renier.jkeepass.JKeePass;
import de.renier.jkeepass.Messages;

/**
 * TogglePasswordVisibilityInTableAction
 *
 * @author <a href="mailto:software@renier.de">Renier Roth</a>
 */
public class TogglePasswordVisibilityInTableAction extends AbstractAction {

  private static final long serialVersionUID = 5359448426060143028L;
  private static final ImageIcon ICON_PASS_SHOW = new ImageIcon(TogglePasswordVisibilityInTableAction.class.getResource("/org/javalobby/icons/20x20/UnLock.gif")); //$NON-NLS-1$
  private static final ImageIcon ICON_PASS_HIDE = new ImageIcon(TogglePasswordVisibilityInTableAction.class.getResource("/org/javalobby/icons/20x20/Lock.gif")); //$NON-NLS-1$
  
  private static final String TEXT_PASS_SHOW = Messages.getString("TogglePasswordVisibilityInTableAction.2"); //$NON-NLS-1$
  private static final String TEXT_PASS_HIDE = Messages.getString("TogglePasswordVisibilityInTableAction.3"); //$NON-NLS-1$
  
  public TogglePasswordVisibilityInTableAction() {
    super(TEXT_PASS_SHOW, ICON_PASS_SHOW);
    this.setEnabled(true);
  }
  
  /* (non-Javadoc)
   * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
   */
  public void actionPerformed(ActionEvent e) {
    // input dialog for container
    boolean state = JKeePass.application.getContainerElementPanel().togglePasswordVisibility();
    if (state) {
      this.putValue(SMALL_ICON, ICON_PASS_HIDE);
      this.putValue(NAME, TEXT_PASS_HIDE);
    } else {
      this.putValue(SMALL_ICON, ICON_PASS_SHOW);
      this.putValue(NAME, TEXT_PASS_SHOW);
    }
  }

}
